import { jobSpread } from "./spread";

export const jobRangedAttack = {
    /**
     * 
     * @param {Creep} creep 
     * @param {Array<AnyCreep | AnyStructure>} targets 
     * @param {MoveToOpts} opts 
     * @returns {CreepActionReturnCode}
     */
    run(creep, targets, opts){
        if(opts===undefined){
            opts = {visualizePathStyle:{stroke:"#ff0000"}};
        }
        if(targets.length === 0){
            return jobSpread.run(creep);
        }
        for(let target of targets){
            if(creep.pos.getRangeTo(target.pos)<=3){
                return creep.rangedMassAttack();
            }
        }
        let ret;
        for(let target of targets){
            ret = creep.rangedAttack(target);
            if(ret === OK){
                return OK;
            }
        }
        return ret;
    }
}